package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateSubjectDialog;
import pl.prv.polanie.client.dto.CSSubjectDTO;
import pl.prv.polanie.client.dto.CSVSubjectDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableSubjects;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class SubjectsList extends ObjectsList {
	
	
	TableSubjects tableSubjects = new TableSubjects(this);

	public SubjectsList() {
		
		CSSubjectDTO[] ls = Cache.getAllSubjects();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableSubjects);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSSubjectDTO cs = ls[i];
			CSVSubjectDTO csv = ViewDataProvider.getCSVSubject(cs);
			
			tableSubjects.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateSubjectDialog cld = new CreateSubjectDialog(SubjectsList.this, null); 
				cld.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableSubjects.removeSelectedSubjectFromTable();
			}
		});

		setupButtons();
	}
	
	public void addCSsubject(CSSubjectDTO csSubject) {
		
		tableSubjects.saveOrUpdateSubjectInTable(csSubject);
//		tableAcademicTitles.addRow(csLecturer, csv);
	}
	
}
